﻿<%@ WebHandler Language="C#" Class="DateJudgement" %>

using System;
using System.Web;

public class DateJudgement : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        if (string.IsNullOrEmpty(context.Request["Type"]) || string.IsNullOrEmpty(context.Request["Date"]))
        {
            context.Response.Write("false");
        }
        else
        {
            string type = context.Request["Type"].ToLower();
            DateTime date = Convert.ToDateTime(context.Request["Date"]);
            switch (type)
            {
                case "weekend":
                    if (date.DayOfWeek == DayOfWeek.Sunday || date.DayOfWeek == DayOfWeek.Saturday)
                        context.Response.Write("true");
                    else
                        context.Response.Write("false");
                    break;
                case "holiday":
                    Attendences.Framework.Entity.Holiday holiday = new Attendences.Framework.Entity.Holiday(date);
                    if (holiday.Load())
                        context.Response.Write("true");
                    else
                        context.Response.Write("false");
                    break;
                default:
                    context.Response.Write("false");
                    break;
            }
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}